package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.User;
import com.example.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    //又是一个依赖注入
    private UserService userService;

    //查询所有用户列表
    @GetMapping
    public Result list() {
        List<User> userList = userService.list();
        log.info("查询全部用户列表");
        return Result.success(userList);
    }

    //删除传入id对应的用户
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除用户{}", id);
        userService.delete(id);
        return Result.success();
    }

    //添加用户
    @PostMapping
    public Result add(@RequestBody User user) {
        log.info("添加用户{}", user);
        userService.add(user);
        return Result.success();
    }

    //



}